// api.ts
import { AlovaInstance } from './index'
/**
 * @description创建一个Get实例，描述Get请求的信息，用于所有的网络请求
 * 以下代码也可以单独写在一个ts文件里面，然后再api.ts引入之后使用
 * headers 请求头
 * params 参数将会以?的形式拼接在url后面
 * localCache:请求级的缓存模式
 * */
const headers = { 'Content-Type': 'application/json;charset=UTF-8' }
// 请求超时时间
const timeout = 5000
 
const Alova = {
// 这是get请求
  createTodoGet(url: string, params: Record<string, any>,time:number) {
    return AlovaInstance.Get(url, {
      headers,
      params,
      localCache: {
        mode: 'placeholder', // 设置缓存模式为持久化占位模式
        expire: time * 1000 * 60 * 60 // 缓存时间，小时单位
      },
      timeout
    })
  },
// 这是post请求
  createTodoPost(url: string, data: Record<string, any>, params: Record<string, any>) {
    return AlovaInstance.Post(url, data, {
      params
    })
  }
// .... 根据需求封装 put delete 等等网络请求
}
 
 
export const _home = {
    getHisList(param: Record<string, any>) {
      return Alova.createTodoGet('home_his.php', param,0)
    },
    getList(param: Record<string, any>) {
      return Alova.createTodoGet('home_list.php', param,0)
    },
    getTags(param: Record<string, any>) {
        return Alova.createTodoGet('all_tags.php', param,24*365)
    },
    getEps(param: Record<string, any>) {
        return Alova.createTodoGet('home_eps.php', param,0)
    },
}

export const _search = {
    getTags(param: Record<string, any>) {
        return Alova.createTodoGet('all_tags.php', param,24*365)
    },
    getList(param: Record<string, any>) {
      return Alova.createTodoGet('all_list.php', param,1)
    },
}

export const _history = {
    getList(param: Record<string, any>) {
        return Alova.createTodoGet('his_list.php', param,0)
    },
    delList(param: Record<string, any>) {
        return Alova.createTodoGet('his_del.php', param,0)
    },
    addHis(param: Record<string, any>) {
        return Alova.createTodoGet('his_add.php', param,0)
    },
}

export const _detail = {
  animes_dtl(param: Record<string, any>) {
      return Alova.createTodoGet('animes_dtl.php', param,0)
  },
  video_dtl(param: Record<string, any>) {
      return Alova.createTodoGet('video_dtl.php', param,0)
  },
  comic_dtl(param: Record<string, any>) {
      return Alova.createTodoGet('comic_dtl.php', param,0)
  },
  fav_add(param: Record<string, any>) {
      return Alova.createTodoGet('fav_add.php', param,0)
  },
}

export const _mylike = {
  mylike_tags(param: Record<string, any>) {
    return Alova.createTodoGet('mylike_tags.php', param,0)
  },
  mylike_addtag(param: Record<string, any>) {
    return Alova.createTodoGet('mylike_addtag.php', param,0)
  },
  mylike_add(param: Record<string, any>) {
    return Alova.createTodoGet('mylike_add.php', param,0)
  },
  mylike_del(param: Record<string, any>) {
    return Alova.createTodoGet('mylike_del.php', param,0)
  },
  mylike_list(param: Record<string, any>) {
    return Alova.createTodoGet('mylike_list.php', param,0)
  },
}

export const _reset = {
  reset_video(param: Record<string, any>) {
    return Alova.createTodoGet('video_type.php', param,0)
  },
  reset_video_cover(param: Record<string, any>) {
    return Alova.createTodoGet('video_cover.php', param,0)
  },
}